package pers.wwz.study.spriingcloudfeign.servicea.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestContextHolder;
import pers.wwz.study.spriingcloudfeign.servicea.feign.ServicebFeign;

import javax.servlet.http.HttpServletRequest;

import java.util.concurrent.atomic.AtomicReference;

import static pers.wwz.study.spriingcloudfeign.servicea.constant.Constants.LOGIN_TOKEN;

@Slf4j
@RestController
@RequestMapping("/servicea")
public class Controllera {

    @Autowired
    ServicebFeign servicebFeign;


    @RequestMapping("/getUuid")
    public String getUuid(){
        return servicebFeign.getUuid();
    }

    @RequestMapping("/getUuidAfterMainFinished")
    public String getUuidAfterMainFinished(HttpServletRequest  httpServletRequest){
        AtomicReference<String> uuid = new AtomicReference<>("");
        String loginToken = httpServletRequest.getHeader(LOGIN_TOKEN);
        log.info("servicea获取请求头参数loginToken:{}",loginToken);
        //RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
        RequestContextHolder.setRequestAttributes(RequestContextHolder.getRequestAttributes(),true);
        new Thread(() -> {
            uuid.set(servicebFeign.getUuid());
            log.info("resp: {}", uuid);
        }).start();
        return uuid.get();
    }
}
